-
-
Notifications
You must be signed in to change notification settings - Fork 53
fix: don't error on circular eslint plugins #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replaces `JSON.stringify` with an implementation from `flatted` for cache keys.
Test failures seem to be exclusive to Eslint 8.x builds (probably to do with the test plugin I create in |
After some investigation, this just seems to be a result of Would you be alright with me just restricting the test case to only ESLint ^9.x (using the same design as If so, please let me know how you'd like me to provide that change (additional commit? new PR? etc). |
I am fine with it |
Done. I've tested the new version locally on ESLint 8.x based on the github workflows; hopefully my setup is close enough to the actual workflows that it runs properly now. |
/cc @ricardogobbosouza can you look at this? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #277 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 291 307 +16
Branches 81 84 +3
=========================================
+ Hits 291 307 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@Josh194 ping me after 3 days if we don't get feedback from @ricardogobbosouza, thank you |
Thanks @Josh194 |
This PR contains a:
Motivation / Use-Case
Previously, attempting to use an overridden config containing a plugin with a circular structure (as is suggested for flat configs) would error, as the caching implementation would attempt to
JSON.stringify
said plugins in order to use them as cache keys.This PR fixes the issue by using
flatted
to perform the conversion instead, which is capable of handling circular objects.A test case (verified to error without the fix) is also included.
Fixes: #270.
Breaking Changes
None.
Additional Info
The changes to
jsonStringifyReplacerSortKeys
are required as returning new objects from the replacer function causesflatted
to enter an infinite loop as it attempts to deal with the ever expanding set of references, eventually running out of memory. I address that by overwriting the object in-place; I'd strongly recommend giving those specific changes a good look, as any mistakes could corrupt the options object for all later code. In particular, I'm not 100% sure ifObject.assign
is the best option here, but it could be completely fine.Test case plugin code is taken almost exactly from https://eslint.org/docs/latest/extend/plugin-migration-flat-config#migrating-configs-for-flat-config; it is probably possible to make it a bit shorter, but I didn't bother to look into it.
npm run test
was run immediately prior to the final (and only) commit, so any stylistic lints should have been applied, but apologies if I've missed anything.